// 封装localStorage 添加过期时间
interface IData {
    expire?:number // 过期时间
    [key:string]:any
} 

export default {
    set(key:string,expire:IData) :void{
      console.log(expire,'expire')
      if(expire){
        const data:IData = {
          ...expire,
        }
        console.log(new Date().getTime(),'new Date().getTime()')
        data.expire = new Date().getTime() + Number(expire.expire) * 1000
        console.log(Number(expire.expire) * 1000,'Number(expire.expire) * 1000')
        console.log(data.expire,'data.expire')
        localStorage.setItem(key,JSON.stringify(data))
      }
    },


    get(key:string){
        const data = localStorage.getItem(key)
        if(data){
            const item =  JSON.parse(data)
            if(item.expire < new Date().getTime()){
                localStorage.removeItem(key)
                return null

            }
            return item
        }

        return null
    }
}